import numpy as np
import cv2
import matplotlib.pyplot as plt
import math


def imageAdd(img1, img2):
	#image_save = cv2.resize(img2, (1300, 1300), interpolation=cv2.INTER_CUBIC)
	#print(image_save.shape)
	#cv2.imwrite("../images/fruits2.png", image_save)
	#print(img1.shape, img2.shape)
	image_add = img1 + img2*0.5
	return image_add


def imageSub(img1, img2):
	image_sub = img1 - img2
	return image_sub
	

def imageMultiply(img1, img2):
	image_mul = img1 * img2
	return image_mul

if __name__ == '__main__':
	img1 = cv2.imread("../images/airplane.png",)
	img2 = cv2.imread("../images/fruits2.png",)

	img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
	img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
	img1  = img1 / 255.0
	img2  = img2 / 255.0
	print(img1.dtype)

	# 两幅图像相加，一个为前景、一个为背景
	add_image = imageAdd(img1, img2)

	# 混合图像与背景图像做减法
	sub_image = imageSub(add_image, img2*0.5)

	# 图像与模板相乘，实现图像局部显示
	mask = np.zeros((1300, 1300, 3))
	mask[300:800, 30:1200] = 1
	mask.astype(np.float64)
	print(mask.dtype)
	mul_image = imageMultiply(img1, mask)



	plt.subplot(131),plt.imshow(add_image)
	plt.title('Input Image1'), plt.xticks([]), plt.yticks([])

	plt.subplot(132),plt.imshow(sub_image)
	plt.title('Input Image1'), plt.xticks([]), plt.yticks([])

	plt.subplot(133),plt.imshow(mul_image)
	plt.title('Input Image1'), plt.xticks([]), plt.yticks([])
	plt.show()